package com.fanfanwang.ffw.app.fragment;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.fanfanwang.ffw.app.AppContext;
import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.adapter.ServiceListAdapter;
import com.fanfanwang.ffw.app.base.BaseFragment;
import com.fanfanwang.ffw.app.bean.ServiceBean;
import com.fanfanwang.ffw.app.ui.service.FourStoreNearListAct;
import com.fanfanwang.ffw.app.ui.service.GasStationListAct;
import com.fanfanwang.ffw.app.ui.service.ServiceAdviceAct;
import com.fanfanwang.ffw.app.ui.service.ServiceCarWashListAct;
import com.fanfanwang.ffw.app.ui.service.ServiceNewListAct;
import com.fanfanwang.ffw.app.ui.service.ServiceYuYueListAct;
import com.fanfanwang.ffw.app.widget.CommonTitleBar;

@SuppressLint({ "ValidFragment", "ResourceAsColor" }) public class MainServiceFragment extends BaseFragment implements OnClickListener{
	
	private LayoutInflater inflater;
	private ListView listview;
	private ServiceListAdapter serviceAdapter;
	private ArrayList<ServiceBean> serviceLists;
	private CommonTitleBar commonTitleBar;
	private Context context;
	Intent intent;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View contactsLayout = inflater.inflate(R.layout.fragment_service_layout,
				container, false);

		return contactsLayout;
	}

	public MainServiceFragment() {
		super();
		// TODO Auto-generated constructor stub
	}
	public static MainServiceFragment getServiceFragment(Context context) {

		MainServiceFragment  clientFragment = new MainServiceFragment(context);
		return clientFragment;
	}
	public MainServiceFragment(Context context) {
		super();
		inflater = LayoutInflater.from(context);
		this.context=context;

	}

	@SuppressLint("NewApi") @Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		getActivity().getWindow().setFormat(PixelFormat.TRANSLUCENT);
//		initView(view);
//		initData();
//		setListener();
	}
	@Override
	public void onResume() {
		super.onResume();
	}




	@Override
	public void setListener() {
		// TODO Auto-generated method stub
		listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long id) {
				//TODO
				switch (pos) {
				case 0:
					intent=new Intent(getActivity(),ServiceCarWashListAct.class);
					getActivity().startActivity(intent);
					break;
				case 1:
					intent=new Intent(getActivity(),FourStoreNearListAct.class);
					getActivity().startActivity(intent);
					break;
				case 2:
					intent=new Intent(getActivity(),GasStationListAct.class);
					getActivity().startActivity(intent);
					break;
				case 3:
					intent=new Intent(getActivity(),ServiceYuYueListAct.class);
					getActivity().startActivity(intent);
					break;
				case 4:
					intent=new Intent(getActivity(),ServiceAdviceAct.class);
					getActivity().startActivity(intent);
					break;
				case 5:
					intent=new Intent(getActivity(),ServiceNewListAct.class);
					getActivity().startActivity(intent);
					break;
				default:
					break;
				}
			}
		});

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

	@Override
	public void initView(View view) {
		// TODO Auto-generated method stub
		listview=(ListView)view.findViewById(R.id.service_listView);
		serviceLists = new ArrayList<ServiceBean>();
		commonTitleBar = (CommonTitleBar) view.findViewById(R.id.common_titlebar);

	}

	@Override
	public void initData() {
		commonTitleBar.setCenterText(getString(R.string.main_tab_service));
		getListData();
		serviceAdapter=new ServiceListAdapter(getActivity(), serviceLists);
		listview.setAdapter(serviceAdapter);

	}
	public void getListData(){
		ServiceBean serviceBean1=new ServiceBean();
		serviceBean1.serviceTitle=getString(R.string.washcar_title);
		serviceBean1.serviceContent=getString(R.string.washcar_content);
		serviceBean1.imageViewId=R.drawable.service_item1;
		//		serviceBean1.imageViewId=R.drawable.ic_launcher;
		ServiceBean serviceBean2=new ServiceBean();
		serviceBean2.serviceTitle=getString(R.string.nearby_store_title);
		serviceBean2.serviceContent=getString(R.string.nearby_store_content);
		serviceBean2.imageViewId=R.drawable.service_item2;
		ServiceBean serviceBean3=new ServiceBean();
		serviceBean3.serviceTitle=getString(R.string.gas_title);
		serviceBean3.serviceContent=getString(R.string.gas_content);
		serviceBean3.imageViewId=R.drawable.service_item3;
		ServiceBean serviceBean4=new ServiceBean();
		serviceBean4.serviceTitle=getString(R.string.yuyue_title);
		serviceBean4.serviceContent=getString(R.string.yeuyue_content);
		serviceBean4.imageViewId=R.drawable.service_item4;
		ServiceBean serviceBean5=new ServiceBean();
		serviceBean5.serviceTitle=getString(R.string.advice_title);
		serviceBean5.serviceContent=getString(R.string.advice_content);
		serviceBean5.imageViewId=R.drawable.service_item5;
		ServiceBean serviceBean6=new ServiceBean();
		serviceBean6.serviceTitle=getString(R.string.car_title);
		serviceBean6.serviceContent=getString(R.string.car_content);
		serviceBean6.imageViewId=R.drawable.service_item6;
		serviceLists.add(serviceBean1);
		serviceLists.add(serviceBean2);
		serviceLists.add(serviceBean3);
		serviceLists.add(serviceBean4);
		serviceLists.add(serviceBean5);
		serviceLists.add(serviceBean6);
	}
	
}
